/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package data;

import com.sun.media.jai.codec.FileSeekableStream;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.SeekableStream;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;

/**
 *
 * @author bertram
 */
public class TiffConverter {
    public TiffConverter()
    {

    }
    public RenderedImage[] readTiff(String fileName)throws IOException
    {
        SeekableStream seekableStream = null;

            File file = new File(fileName);
            seekableStream = new FileSeekableStream(file);
            ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", seekableStream, null);
            int numPages = decoder.getNumPages();
            RenderedImage[] image = new RenderedImage[numPages];
            int count = 0;
            for (int i = 0; i < decoder.getNumPages(); i++) {
                image[i] = decoder.decodeAsRenderedImage(i);
                count++;
            }
            /*for (int i = 0; i < count; i++) {
                RenderedImage page = decoder.decodeAsRenderedImage(i);
                ParameterBlock parBlock = new ParameterBlock();
                parBlock.addSource(page);
                parBlock.add("png");
                RenderedOp renderedOp = JAI.create("filestore", parBlock);
                renderedOp.dispose();
            }*/


     return image;
}

}
